function getUrl(last) {
   var host = 'www.maksdu.com/app';
   return 'https://'+host+'/'+last;
}

function saveEquip() {
	$.ajax({
		url:getUrl('equip/new'),
		type:'post',
		data: {
			ip:$('#equipIp').val(),
			source:$('#equipSource').val(),
			description:$('#equipDescription').val()
		},
		success:function(data) {
			if(data) {
				$("#mytable").bootstrapTable('refresh');
			}
		}
	});
}

function init() {
	var now = new Date();  
	var day = ("0" + now.getDate()).slice(-2);  
	//格式化月，如果小于9，前面补0  
	var month = ("0" + (now.getMonth() + 1)).slice(-2);  
	//拼装完整日期格式  
	var today = now.getFullYear()+"-"+(month)+"-"+(day) ;  
	//完成赋值  
	$("#birth").val(today); 
	$("#inday").val(today); 
}

function update_status() {

}

function save() {
	var name = $("input[name='name']").val();
	if(!name) {
		alert("抱歉，您的姓名还未输入");
		return;
	}
	$.ajax({
		url:getUrl('save'),
		type: 'post',
		data: $("#form").serialize(),
		success: function(data) {
			if(data) {
				window.location.reload();
			}
		}
	})
}

function department_load() {
	var dpt = $("#department");
	$.ajax({
		url:getUrl('department/list'),
		method:'get',
		success:function(data) {
			if(data) {
				dpt.empty();
				data.forEach(function(element,index){
					dpt.append("<option value="+element.departName+">"+element.departName+"</option>")
				})
			}
		}
	});
}

function update_status(ids) {
	if(confirm('确定要修改员工的状态吗？')) { 
	    $.ajax({
			url:getUrl('update'),
			type: 'post',
			data: {
				id: ids
			},
			success:function(data) {
				if(data) {
					window.location.reload();
				}
			}
		});
	} 
	return false; 
}

function DeleteEquipByIds(ids) {
	if(confirm('确定要移除该设备记录吗？')) {
		$.ajax({
			url:getUrl('equip/delete'),
			method: 'post',
			data: {
				id: ids
			},
			success:function(data) {
				if(data) {
					$("#mytable").bootstrapTable('refresh');
				}
			}
		});
	}
}

function DeleteUserByIds(ids) {

	if(confirm('确定要封禁该用户吗?')) { 
	    $.ajax({
			url:getUrl('user/delete'),
			method: 'post',
			data: {
				userid: ids
			},
			success:function(data) {
				$("#mytable").bootstrapTable('refresh');
			}
		});
	} 
	return false; 
}

function DeletePostByIds(ids) {
	if(confirm('确定要删除该贴目吗?')) {
		$.ajax({
			url:getUrl('/post/delete'),
			method: 'post',
			data: {
				id: ids
			},
			headers: {
				request_access_token: window.localStorage.getItem('token'),
				request_header_username: window.localStorage.getItem('username')
			},
			success: function(data) {
				if(data.code && data.code == -1) {
					alert("登录无效");
				} else
					$("#mytable").bootstrapTable('refresh');
			}
		})
	}
}

function unBanUserByIds(ids) {

	if(confirm('确定要解除封禁吗?')) { 
	    $.ajax({
			url:getUrl('user/delete'),
			method: 'post',
			data: {
				userid: ids
			},
			success:function(data) {
				$("#mytable").bootstrapTable('refresh');
			}
		});
	} 
	return false; 
}

function getAllUser() {
	
}

function add0(m){return m<10?'0'+m:m }  

function changeDateFormat(cellval) {  
    if (cellval != null) {  
        var time = new Date(cellval);  
	    var year = time.getFullYear();  
	    var month = time.getMonth()+1;  
	    var date = time.getDate();  
	    var hours = time.getHours();  
	    var minutes = time.getMinutes();  
	    var seconds = time.getSeconds();  
	    return year+'-'+add0(month)+'-'+add0(date)+' '+add0(hours)+':'+add0(minutes)+':'+add0(seconds);
    }  
}  

function grant_admin(userid,status) {
	//是管理员
	if(status) {
		grant_user(userid,1);
	} else {
		grant_user(userid,3);
	}
}

function grant_user(userid,roleid) {
	$.ajax({
		url: getUrl('/rp/rgrant'),
		method: 'post',
		data: {
			userid:userid,
			roleid:roleid
		},
		success:function(data) {
			$("#mytable").bootstrapTable('refresh');
		}
	});
}

function add_role(name,value) {
	$.ajax({
		url: getUrl('/rp/addrole'),
		method: 'post',
		data: {
			name: $('#rolename').val(),
			value: $('#rolevalue').val(),
		},
		success:function(data) {
			$("#mytable").bootstrapTable('refresh');
		}
	})
}